#include<iostream>
using namespace std;

//多态实现
//多态优点：代码组织结构清晰，可读性强，利于优化维护。
class AbstractCalculator
{
public:
    virtual int getResult()
    {
        return 0;
    }

    int num_A;
    int num_B;
};

//加法计算器
class AddCalculator:public AbstractCalculator
{
    public:
        int getResult()
        {
            return num_A + num_B;
        }
};

//减法计算器
class SubCalculator:public AbstractCalculator
{
    public:
        int getResult()
        {
            return num_A - num_B;
        }
};


//乘法计算器
class MulCalculator:public AbstractCalculator
{
    public:
        int getResult()
        {
            return num_A * num_B;
        }
};

void test01()
{
    //创建加法计算器
     AbstractCalculator *abc = new AddCalculator;
     abc->num_A=100;
     abc->num_B=500;
     cout <<abc->num_A<<"+"<<abc->num_B<<"="<<abc->getResult()<<endl;
     //手动释放堆区内存,指针地址还在
     delete abc;

  //创建减法计算器
    abc = new SubCalculator;
     abc->num_A=70;
     abc->num_B=30;
     cout <<abc->num_A<<"-"<<abc->num_B<<"="<<abc->getResult()<<endl;
     //手动释放堆区内存,指针地址还在
     delete abc;

       //创建乘法计算器
    abc = new MulCalculator;
     abc->num_A=20;
     abc->num_B=20;
     cout <<abc->num_A<<"*"<<abc->num_B<<"="<<abc->getResult()<<endl;
     //手动释放堆区内存,指针地址还在
     delete abc;

}

int main03(int argc, char const *argv[])
{
    

    test01();

    return 0;
}
